package ui.faces
{
	import global.Managers;
	
	import ui.components.renderlist.RenderList;
	import ui.faces.kitchen.vo.ConfirmedRendererVO;
	import ui.faces.kitchen.vo.UnconfirmedRendererVO;
	
	/**
	 * 该界面为厨房客户端专用
	 * @author Raykid
	 */
	public class KitchenFace extends AbstractFace
	{
		private var _confirmedList				: RenderList;
		private var _unconfirmedList			: RenderList;
		
		public function KitchenFace()
		{
			super();
		}
		override protected function createBG():void {
			super.createBG();
			_bg.addChild(Managers.resourceManager.getBitmap("faces/kitchenBG.jpg"));
		}
		override protected function createView():void {
			super.createView();
			
			_confirmedList = new RenderList();
			_confirmedList.itemNumHorizon = 1;
			_confirmedList.itemNumVerticle = 10;
			_confirmedList.x = 10;
			_confirmedList.y = 10;
			addChild(_confirmedList);
			
			_unconfirmedList = new RenderList();
			_unconfirmedList.itemNumHorizon = 1;
			_unconfirmedList.itemNumVerticle = 10;
			_unconfirmedList.x = 522;
			_unconfirmedList.y = 10;
			addChild(_unconfirmedList);
		}
		override protected function initListener():void {
			super.initListener();
			
			Managers.serverManager.subscribe("UpdateKitchenOrdered", updateKitchenOrderedHandler);
		}
		private function updateKitchenOrderedHandler(data:Object):void {
			var confirmedList:Array = data.confirmed;
			var unconfirmedList:Array = data.unconfirmed;
			var confirmedArr:Array = [];
			var unconfirmedArr:Array = [];
			var i:int;
			var temp:Object
			for(i = 0; i < confirmedList.length; i++) {
				temp = confirmedList[i];
				var confirmedValue:ConfirmedRendererVO = new ConfirmedRendererVO();
				confirmedValue.orderID = temp.id;
				confirmedValue.dishID = temp.dishID;
				confirmedValue.tableID = temp.tableID;
				confirmedValue.pointTime = temp.pointTime;
				confirmedValue.confirmedTableID = temp.confirmedTableID;
				confirmedArr.push(confirmedValue);
			}
			_confirmedList.setDataProvider(confirmedArr);
			for(i = 0; i < unconfirmedList.length; i++) {
				temp = unconfirmedList[i];
				var unconfirmedValue:UnconfirmedRendererVO = new UnconfirmedRendererVO();
				unconfirmedValue.orderID = temp.id;
				unconfirmedValue.dishID = temp.dishID;
				unconfirmedValue.tableID = temp.tableID;
				unconfirmedValue.pointTime = temp.pointTime;
				unconfirmedArr.push(unconfirmedValue);
			}
			_unconfirmedList.setDataProvider(unconfirmedArr);
		}
		
		/**
		 *
		 * 切换语言 
		 * @param toLanguage 切换到的语言
		 * 
		 */
		override public function switchLanguage(toLanguage:int):void
		{
			super.switchLanguage(toLanguage);
			
			if(toLanguage == _currentLanguage) return;
			_currentLanguage = toLanguage;
		}
	}
}